//-----------------------------------------------------------------------------
//  File          : sysutil.h
//  Module        :
//  Description   : Header file for SYSUTIL.C
//  Author        : Lewis
//  Notes         :
//
// ============================================================================
// | Naming conventions                                                       |
// | ~~~~~~~~~~~~~~~~~~                                                       |
// |         Struct/Array : Leading s                                         |
// |             Constant : Leading K                                         |
// |      Global Variable : Leading g  (variable use outside one C file)      |
// |                                                                          |
// |   BYTE( 8 Bits) size : Leading b                                         |
// |   CHAR( 8 Bits) size : Leading c                                         |
// |   WORD(16 Bits) size : Leading w                                         |
// |  DWORD(32 Bits) size : Leading d                                         |
// |    int(32 Bits) size : Leading i                                         |
// | DDWORD(64 Bits) size : Leading dd                                        |
// |              Pointer : Leading p                                         |
// |                                                                          |
// |    Function argument : Leading a                                         |
// |       Local Variable : All lower case                                    |
// |                                                                          |
// | Examples:                                                                |
// |                Array : Leading s, (sb = arrary of byte, etc)             |
// |              Pointer : Leading p, (pb = pointer of byte, etc)            |
// ============================================================================
//
//  Date          Who         Action
//  ------------  ----------- -------------------------------------------------
//  01 Feb  2010  Lewis       Initial Version.
//-----------------------------------------------------------------------------
#ifndef _INC_SYSUTIL_H_
#define _INC_SYSUTIL_H_
#include "common.h"
#include "system.h"
#include "basecall.h"


//-----------------------------------------------------------------------------
//  Delay Functions
//-----------------------------------------------------------------------------
extern void Delay10ms(DWORD aCnt);

//-----------------------------------------------------------------------------
//  Buzzer Functions
//-----------------------------------------------------------------------------
extern void AcceptBeep(void);
extern void LongBeep(void);

//-----------------------------------------------------------------------------
//  Display Functions
//-----------------------------------------------------------------------------
#if (R700 | TIRO | PR608)
#define SU_NOR_LINESIZE          (16)
#define SU_MAX_LINESIZE          (21)
// Line number defines
#define SU_LINE1                 0x0000
#define SU_LINE2                 0x0200
#define SU_LINE3                 0x0400
#define SU_LINE4                 0x0600
#define SU_LINE5                 0x0800
#define SU_LINE6                 0x0A00
#define SU_LINE7                 0x0C00
#define SU_LINE8                 0x0E00
#define SU_LINE9                 0x0000
#define SU_MAX_LINE              SU_LINE8
#endif

#if T800
#define SU_NOR_LINESIZE          (20)
#define SU_MAX_LINESIZE          (26)
// Line number defines
#define SU_LINE1                 0x0100
#define SU_LINE2                 0x0200
#define SU_LINE3                 0x0300
#define SU_LINE4                 0x0400
#define SU_LINE5                 0x0500
#define SU_LINE6                 0x0600
#define SU_LINE7                 0x0700
#define SU_LINE8                 0x0800
#define SU_LINE9                 0x0900
#define SU_MAX_LINE              SU_LINE9
#endif

#if T800
#define LINE_NO(x)             ((x>>8)&0x0F)
#define LINE_POS(x)            ((x&0x00FF)+1)
#else
#define LINE_NO(x)             ((x>>4)&0xE0)
#define LINE_POS(x)            (x&0x001F)
#endif

//-----------------------------------
// SU_SMFONT  => LCD=8x16
// SU_BIGFONT => LCD=4x16
// SU_SPFONT  => LCD=8x21
#define SU_SMFONT               0x0000
#define SU_BIGFONT              0x1000
#define SU_SPFONT               0x2000
#define SU_SPCHI                0x3000
#define SU_8X16FONT             0x4000
#define SU_8X8FONT              0x5000
#define SU_6X8FONT              0x6000
#define SU_8X16TFONT            0x7000
#define MAX_SU_FONT             0x08

// Control
#define SU_LEFT                  0x00
#define SU_RIGHT                 0x01
#define SU_CENTER                0x02

// Option
#define SU_REVERSE               0x10
#define SU_CLREOL                0x20
#define SU_CLRDISP               0x80

extern DWORD ClearLine(DWORD aLineNo, DWORD aReverse);
extern DWORD ClrBelow(DWORD aLineNo);
#define SU_CLRHOME           K_ClrHome
#define SU_REV_ON            K_RevOn
#define SU_REV_OFF           K_RevOff
#define DispCtrl(x)          os_disp_putc(x)

// aOffset = SU_LINEx + offset (from 0 to SU_MAX_LINESIZE-1)
// aCtrl   = SU_xxFont + Option + Control
extern DWORD DispGotoXY(DWORD aOffset, DWORD aFont);
extern DWORD DispLine(const void *aMsg, DWORD aOffset, DWORD aCtrl);

//-----------------------------------------------------------------------------
//    Keyboard Functions
//-----------------------------------------------------------------------------
#define SU_KEY0     K_Key0
#define SU_KEY1     K_Key1
#define SU_KEY2     K_Key2
#define SU_KEY3     K_Key3
#define SU_KEY4     K_Key4
#define SU_KEY5     K_Key5
#define SU_KEY6     K_Key6
#define SU_KEY7     K_Key7
#define SU_KEY8     K_Key8
#define SU_KEY9     K_Key9
#define SU_CLR      K_KeyClr
#define SU_CANCEL   K_KeyCancel
#define SU_ENTER    K_KeyEnter

#if PR608
#define SU_ALPHA    K_KeyFunc
#define SU_FEED     0xFFFF
#define SU_KEY00    0xFFFE
#endif
#if TIRO
#define SU_ALPHA    K_KeyFunc1
#define SU_FEED     0xFFFF
#define SU_KEY00    K_Key00
#endif
#if T800
#define SU_ALPHA    K_KeyFunc1
#define SU_FEED     0xFFFF
#define SU_KEY00    0xFFFE
#endif
#if R700
#define SU_ALPHA    K_KeyLeftHot3
#define SU_FEED     0xFFFF
#define SU_KEY00    0xFFFE
#endif

//-----------------------------------------------------------------------------
//    Misc Functions
//-----------------------------------------------------------------------------
extern void ClrAllFiles(void);
extern void MemFatalErr(void *aMemPtr);

extern void CommitFileIO(void);
extern void CheckPointerAddr(void *aPtr);
extern void DelaySec(DWORD aSec);

#endif // _INC_SYSUTIL_H_

